package br.com.pyramides.dao;

import br.com.pyramides.dao.iface.IEventoDAO;
import br.com.pyramides.model.Evento;
import br.com.pyramides.utils.HibernateUtil;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Lessandro
 */
public class EventoDAO extends GenericDAO<Evento, Long> implements IEventoDAO {

    @Override
    public List<Evento> listaEventos(long idUsuario) {
        Transaction transaction = null;
        Session session = null;
        try {
            session = new HibernateUtil().openSession();
            transaction = session.beginTransaction();
            Criteria criteria = session.createCriteria(Evento.class);
            criteria.add(Restrictions.eq("usuario.idUsuario", idUsuario));
            return criteria.list();
        } catch (Exception ex) {
            transaction.rollback();
        } finally {
            session.clear();
            session.close();
        }
        return null;
    }
}
